<template>
  <view class="container">
    <web-view :src="url" @message="handleMessage"></web-view>
  </view>
</template>

<script setup>
import { ref, onMounted } from "vue";

// 网页URL
const url = ref("");

// 获取页面参数
const getParams = () => {
  const pages = getCurrentPages();
  const currentPage = pages[pages.length - 1];
  const options = currentPage.$page.options;

  if (options.url) {
    url.value = decodeURIComponent(options.url);
  } else {
    // 如果没有传递url参数，跳转回上一页
    uni.navigateBack();
  }
};

// 处理网页消息
const handleMessage = (event) => {
  console.log("WebView message:", event.detail);
};

onMounted(() => {
  getParams();
});
</script>

<style lang="scss">
.container {
  width: 100%;
  height: 100vh;
}
</style>
